$(function(){
    var icon=$(".pic-show>i").attr("class");
    var flag=true;
    $(".openchoose").on("click",function(){
        $(".filter1").css("display","block");
    });
    $(".cancel,.icon-remove-wrap").on("click",function(){
        $(".filter1").css("display","none");
    });

    $(".filter1>ul>li").on("click",function(){
        $(this).addClass("lichosed").siblings().removeClass("lichosed");
    });
    $(".confirm").on("click",function(){
        icon=$(".lichosed>span").html();
        $(".pic-show>input").val(icon);
        $(".filter1").css("display","none");
        $(".pic-show>i").addClass(icon);
    });
    //传递数据
    $(".btn-last-confirm").on("click",function(){
        //被选中的操作
        var chose1=$("input[name=operation]:checked").val();   //操作
        var chose2=$("input[name=is_show]:checked").val();   //是否显示

        var parent=$(".select option:selected").val();  //父级
        var menuName=$(".menu-name").val();
        var menuAddr=$(".menu-addr").val();

        if(menuName==""){
            layer.msg("请输入菜单名称");
            flag=false;
        }else if(menuAddr==""){
            layer.msg("请输入菜单地址");
            flag=false;
        }else if(parent==""){
            layer.msg("请选择菜单父级");
            flag=false;
        }else if(chose1==undefined){
            layer.msg("请选择所需要的操作");
            flag=false;
        }else if(icon==""){
            layer.msg("请选择菜单图标");
            flag=false;
        }else if(chose2==undefined){
            layer.msg("请选择是否需要显示");
            flag=false;
        }else{
            flag=true;
        }
        var datastr="menu_name="+menuName+"&url="+menuAddr+"&parent_code="+parent+"&operation="+chose1+"&icon="+icon+"&is_show="+chose2;
        var datastr=$(".form-horizontal").serialize();
        if(flag==true){
            ajax("post","/menu/update-menu",datastr,function success(data){
                console.log(data)
                if(data.code==200){
                    layer.msg(data.msg);
                    setTimeout(function(){
                        location.href="/menu/index";
                    },1200)
                }else{
                    layer.msg(data.msg);
                }
            })
        }
    });
    $(".btn-last-cancel").on("click",function(){
        location.href='/menu/index';
    });
})